package day15;

public class h1 {
    public static void main(String[] args) throws InterruptedException {
        shop shop=new shop();
        Thread t1=new Thread("a"){
            @Override
            public void run() {
                try {
                    shop.shopping();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        };
        Thread t2=new Thread("b"){
            @Override
            public void run() {
                try {
                    shop.shopping();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        };
            t1.start();
            t2.start();
    }
}
class shop{
     void  shopping() throws InterruptedException {
         Thread t=Thread.currentThread();
        System.out.println(t+"挑选商品");
        Thread.sleep(1000);
        synchronized (this){
            System.out.println(t+"排队结账");
            Thread.sleep(3000);
        }

        System.out.println(t+"结账完成");
    }


}
